﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ResetPassword : System.Web.UI.Page
{
    AccountManager am = new AccountManager();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    private string NoiDungMail()
    {
        string NoiDung = "";
        string MatKhauMoi = Manipulation.RandomKey(7);
        NoiDung = "<b>This is mail be send from website of RailWay Reservation..<hr><br>";
        NoiDung += "New password of your is: " + MatKhauMoi;
        NoiDung += "<br>After logging in you should change your password for easy login next time.";
        NoiDung += "<br><br><hr>Please do not reply this mail!";

        return NoiDung;
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        //xu li CSDL
        string from_address = "hongquocan@gmail.com";
        string from_password = "anhyeuemmaimai";
        string display_name = "Railway Reservation";
        string emp_number = txtUserName.Text;
        string to_address = txtEmail.Text;
        string subject_mail = "Provided for password user";
        //string body = NoiDungMail();
        string body = "";
        string MatKhauMoi = Manipulation.RandomKey(7);
        body = "<b>This is mail be send from website of RailWay Reservation</b>..<hr><br>";
        body += "New password of your is: " + MatKhauMoi;
        body += "<br>After logging in you should change your password for easy login next time.";
        body += "<br><br><hr>Please do not reply this mail!";

        if (am.ResetPassword(emp_number, MatKhauMoi, to_address) > 0)
        {
            Session["email_getpass"] = to_address;
            if (Manipulation.SendMail(from_address, from_password, display_name, to_address, subject_mail, body))
            {
                //send mail successful
                Response.Write("<script>alert('thanh cong!')</script>");
            }
            else
            {
                //send mail faild
                Response.Write("<script>alert('Sorry, system error.Please try again!')</script>");
            }
        }
        else
        {
            lblMessage.Text = "You provided information not valid";
        }
    }
}